var text=""
var text2=""
var correspondingArea={}
var correspondingAreaarr=[]
var contactusID=sessionStorage.getItem("contactusID")
var addressarr={}
/*查询对应区域*/
correspondingAreas()
function correspondingAreas() {
    $.ajax({
        type: "POST",
        url: root.brandWebsite.getBrandWebsiteArea,
        cache: false,  //禁用缓存
        dataType: "json",
        data: {
            "websiteId":contactusID,
        },
        success: function (data) {
            correspondingAreaarr=[]
            correspondingAreaarr=addressarr
            for(var e=0;e<data.data.brandWebsiteAreaDtos.length;e++){
                $.each(correspondingAreaarr,function(k,v) {
                    if (data.data.brandWebsiteAreaDtos[e].areaId ==v.areaId){
                        v.areaLinkMsg=data.data.brandWebsiteAreaDtos[e].areaLinkMsg
                    }
                        })
            }
            console.log(correspondingAreaarr)

            $("#pageTitle").val(data.data.pageTitle)
            $("#pageDescription").val(data.data.pageDescription)
            $("#pageKeywords").val(data.data.pageKeywords)
            ue2.ready(function() {
                text2 = ue2.setContent(data.data.websiteContactDetails);
            });
        },
        error: function () {
            $.Huimodalalert('失败！',2000);
        }
    });
    addressarr=[{
        "areaId":100,
        "areaName":"北京市",
        "areaLinkMsg":""
    },
        {
        "areaId":101,
        "areaName":"上海市",
            "areaLinkMsg":""
        },
        {
            "areaId":102,
            "areaName":"天津市",
            "areaLinkMsg":""
        }, {
            "areaId":103,
            "areaName":"重庆市",
            "areaLinkMsg":""
        },
        {
            "areaId":104,
            "areaName":"河北省",
            "areaLinkMsg":""
        },
        {
            "areaId":105,
            "areaName":"山西省",
            "areaLinkMsg":""
        },
        {
            "areaId":106,
            "areaName":"吉林省",
            "areaLinkMsg":""
        },
        {
            "areaId":107,
            "areaName":"辽宁省",
            "areaLinkMsg":""
        },
        {
            "areaId":108,
            "areaName":"黑龙江省",
            "areaLinkMsg":""
        },{
            "areaId":109,
            "areaName":"陕西省",
            "areaLinkMsg":""
        },{
            "areaId":110,
            "areaName":"甘肃省",
            "areaLinkMsg":""
        },
        {
            "areaId":111,
            "areaName":"青海省",
            "areaLinkMsg":""
        },
        {
            "areaId":112,
            "areaName":"山东省",
            "areaLinkMsg":""
        },
        {
            "areaId":113,
            "areaName":"福建省",
            "areaLinkMsg":""
        },
        {
            "areaId":114,
            "areaName":"浙江省",
            "areaLinkMsg":""
        },
        {
            "areaId":115,
            "areaName":"台湾省",
            "areaLinkMsg":""
        },
        {
            "areaId":116,
            "areaName":"河南省",
            "areaLinkMsg":""
        },
        {
            "areaId":117,
            "areaName":"湖北省",
            "areaLinkMsg":""
        },
        {
            "areaId":118,
            "areaName":"湖南省",
            "areaLinkMsg":""
        },
        {
            "areaId":119,
            "areaName":"江西省",
            "areaLinkMsg":""
        },
        {
            "areaId":120,
            "areaName":"江苏省",
            "areaLinkMsg":""
        },
        {
            "areaId":121,
            "areaName":"安徽省",
            "areaLinkMsg":""
        },
        {
            "areaId":122,
            "areaName":"广东省",
            "areaLinkMsg":""
        },
        {
            "areaId":123,
            "areaName":"海南省",
            "areaLinkMsg":""
        },
        {
            "areaId":124,
            "areaName":"四川省",
            "areaLinkMsg":""
        },
        {
            "areaId":125,
            "areaName":"贵州省",
            "areaLinkMsg":""
        },

        {
            "areaId":126,
            "areaName":"云南省",
            "areaLinkMsg":""
        },
        {
            "areaId":127,
            "areaName":"内蒙",
            "areaLinkMsg":""
        },
        {
            "areaId":128,
            "areaName":"新疆",
            "areaLinkMsg":""
        },
        {
            "areaId":129,
            "areaName":"宁夏",
            "areaLinkMsg":""
        },
        {
            "areaId":130,
            "areaName":"广西",
            "areaLinkMsg":""
        },
        {
            "areaId":131,
            "areaName":"西藏",
            "areaLinkMsg":""
        },

        {
            "areaId":132,
            "areaName":"香港",
            "areaLinkMsg":""
        },
        {
            "areaId":133,
            "areaName":"澳门",
            "areaLinkMsg":""
        }


    ]

          var correspondingAreas=""
           console.log(addressarr)
            $.each(addressarr,function(k,v){
                correspondingAreas += '<li class="clearfix pl-10 mb-5 ml-10 correspondingArea" style="float: left;margin-left: 133px;">' +
                    '                            <div class="f-l pd-5">' +
                    '                                <input  name="classification01" type="radio" value="'+v.areaId+'" onclick="contentAll('+v.areaId+',this)" class="radio">' +
                    '                                    <label class="pl-10"><input title="" type="text" class="addressname" value="'+v.areaName+'" disabled="" style="height: 24px;width: 99px;border: 0px;background: white;margin-top: -4px">' +
                    '                                    <a id="preservation'+v.areaId+'" style="display: none" class="preservations" onclick="preservations('+v.areaId+',this)">保存</a>' +
                    '                                    <span id="information'+v.areaId+'" style="display: none" class="information"></span>' +
                    '                                    </label>' +
                    '                                    </div>' +
                    '                                    </div>' +
                    '                    </li>'
            })


            $("#correspondingArea").html(correspondingAreas)


}
//切换区域
function contentAll(val,e){
    for (var i=0;i<correspondingAreaarr.length;i++){

        if(correspondingAreaarr[i].areaId==val){
            ue.ready(function() {
                ue.setContent(correspondingAreaarr[i].areaLinkMsg);
            });
        }

    }
    $(e).parent().find(".preservations").css({display:"inline"})
    $(e).parent().parent().siblings().find(".preservations").css({display:"none"})
}

//保存
function preservations(val,e) {
    console.log(correspondingAreaarr)
    //获取富文本值
    ue.ready(function() {
        text = ue.getContent();
    });
    console.log(text)
    $("#information"+val).html(text)
    $(e).parent().find(".preservations").css({display:"none"})
    //获取数据
    var classdatas= $("#correspondingArea").find(".correspondingArea");

    $.each(correspondingAreaarr,function(k,v){
        if(val==v.areaId){
            v.areaLinkMsg=text
        }
    })
   console.log(correspondingAreaarr)



}
//确定

function determine() {
    ue2.ready(function() {
        text2 = ue2.getContent();
    });

    console.log(correspondingAreaarr)
    $.ajax({
        type: "POST",
        url: root.brandWebsite.saveBrandWebsiteArea,
        cache: false,  //禁用缓存
        dataType: "json",
        contentType: "application/json",
        data: JSON.stringify({
            "websiteId":contactusID,
            "pageTitle":$("#pageTitle").val(),
            "pageDescription":$("#pageDescription").val(),
            "pageKeywords":$("#pageKeywords").val(),
            "createUser":JSON.parse(decodeURIComponent(web.readCookie("loginData"))).user.name,
            "websiteContactDetails":text2,
            "brandWebsiteAreaDtos":correspondingAreaarr
        }),
        success: function (data) {
            if(data.errorCode==0){
                layer.msg("修改成功",{icon: 6,time:2000},function () {
                    setTimeout(function () {
                        window.parent.contactUsquerys();
                        var index = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(index);
                    })
                });
            }else {
                layer.msg(data.msg, {icon: 5,time:1000});
            }
        },
        error: function () {
            $.Huimodalalert('失败！',2000);
        }
    });
}
/*ue2.ready(function() {
       text2 = ue2.getContent();
   });
   console.log(text2)*/
